<template>
  <div class="container">
    <div class="info-box">
      <van-image
        width="64"
        height="64"
        round
        fit="cover"
        :src="userInfo.photo"
      />
      <h2 class="name">
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" color="#fff" text-color="#3296fa">
          {{ userInfo.birthday }}
        </van-tag>
      </h2>
    </div>
    <van-row class="user-nav">
      <van-col span="8">
        <van-icon name="newspaper-o" color="#7af" />我的作品
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#f00" />我的收藏
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#fa0" />阅读历史
      </van-col>
    </van-row>
    <van-cell-group>
      <van-cell
        icon="edit"
        title="编辑资料"
        isLink
        @click="$router.push('/edit')"
      />
      <van-cell icon="smile-o" title="小智同学" isLink />
      <van-cell icon="setting-o" title="系统设置" isLink />
      <van-cell icon="warning-o" title="退出登录" isLink @click="logOutClick" />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from "./user.js";
import { removeToken } from "@/utils/token.js";
export default {
  name: "user",
  data() {
    return {
      userInfo: {},
    };
  },
  created() {
    getUserInfo().then((res) => {
      console.log(res);
      this.userInfo = res.data.data;
      //   console.log(this.userInfo);
      this.$store.commit("setUserInfo", res.data.data);
    });
  },
  methods: {
    logOutClick() {
      this.$dialog
        .confirm({
          title: "退出内容",
          message: "确定退出?",
        })
        .then(() => {
          console.log("then");
          removeToken();
          this.userInfo = {};
          this.$router.push({ path: "/login" });
        })
        .catch(() => {
          console.log("catch");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  .info-box {
    height: 100px;
    background-color: pink;
    display: flex;
    align-items: center;
    padding-left: 15px;
    .name {
      font-size: 20px;
      padding-left: 15px;
      color: white;
      font-weight: normal;
    }
  }
  .user-nav {
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    padding: 15px;
    .van-icon {
      display: block;
      font-size: 24px;
      padding-bottom: 5px;
    }
  }
}
</style>